package com.ruoyi.experiment.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.experiment.domain.SampleMailing;
import com.ruoyi.experiment.model.SampleMailings;
import com.ruoyi.experiment.service.ISampleMailingService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 样品邮寄Controller
 *
 * @author ruoyi
 * @date 2024-06-07
 */
@RestController
@RequestMapping("/experiment/mail")
public class SampleMailingController extends BaseController
{
    @Autowired
    private ISampleMailingService sampleMailingService;

    /**
     * 查询样品邮寄列表
     */
    // @PreAuthorize("@ss.hasPermi('system:mailing:list')")
    @GetMapping("/list")
    public TableDataInfo list(SampleMailing sampleMailing)
    {
        startPage();
        List<SampleMailing> list = sampleMailingService.selectSampleMailingList(sampleMailing);
        return getDataTable(list);
    }

    /**
     * 导出样品邮寄列表
     */
    // @PreAuthorize("@ss.hasPermi('system:mailing:export')")
    @Log(title = "样品邮寄", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SampleMailing sampleMailing)
    {
        List<SampleMailing> list = sampleMailingService.selectSampleMailingList(sampleMailing);
        ExcelUtil<SampleMailing> util = new ExcelUtil<SampleMailing>(SampleMailing.class);
        util.exportExcel(response, list, "样品邮寄数据");
    }

    /**
     * 获取样品邮寄详细信息
     */
    // @PreAuthorize("@ss.hasPermi('system:mailing:query')")
    @GetMapping(value = "/{mailingId}")
    public AjaxResult getInfo(@PathVariable("mailingId") Long mailingId)
    {
        return success(sampleMailingService.selectSampleMailingByMailingId(mailingId));
    }

    /**
     * 新增样品邮寄
     */
    // @PreAuthorize("@ss.hasPermi('system:mailing:add')")
    @Log(title = "样品邮寄", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SampleMailing sampleMailing)
    {
        return toAjax(sampleMailingService.insertSampleMailing(sampleMailing));
    }
    /**
     * 批量添加样品邮寄
     */
    @Log(title = "样品邮寄", businessType = BusinessType.INSERT)
    @PostMapping("adds")
    public AjaxResult adds(@RequestBody SampleMailings sampleMailings)
    {
        for (Long id : sampleMailings.getIds()) {
            sampleMailings.setSampleId(id);
            sampleMailingService.insertSampleMailing(sampleMailings);
        }
        return success();
    }

    /**
     * 修改样品邮寄
     */
    // @PreAuthorize("@ss.hasPermi('system:mailing:edit')")
    @Log(title = "样品邮寄", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SampleMailing sampleMailing)
    {
        return toAjax(sampleMailingService.updateSampleMailing(sampleMailing));
    }

    /**
     * 删除样品邮寄
     */
    // @PreAuthorize("@ss.hasPermi('system:mailing:remove')")
    @Log(title = "样品邮寄", businessType = BusinessType.DELETE)
    @DeleteMapping("/{mailingIds}")
    public AjaxResult remove(@PathVariable Long[] mailingIds)
    {
        return toAjax(sampleMailingService.deleteSampleMailingByMailingIds(mailingIds));
    }
}

